package com.smart.persistence.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "T_Hotel")
@NamedQueries({
		@NamedQuery(name = Hotel.findFullHotelByCodeHotel, query = "SELECT  entity  FROM Hotel entity where  entity.codHotel = ?1 and entity.latitude is not null"),
		@NamedQuery(name = Hotel.findEmptyHotel, query = "SELECT  entity  FROM Hotel entity where entity.latitude is null"),
		@NamedQuery(name = Hotel.findByCodeHotel, query = "SELECT  entity  FROM Hotel entity where  entity.codHotel = ?1")

})
public class Hotel {

	public static final String findEmptyHotel = "Hotel.findEmpityHotelByCodeHotel";
	public static final String findFullHotelByCodeHotel = "Hotel.findFullHotelByCodeHotel";
	public static final String findByCodeHotel = "Hotel.findByCodeHotel";

	@Id
	@Column(name = "id_hotel")
	@TableGenerator(name = "HOTEL_GEN", allocationSize = 1, initialValue = 1, table = "T_ID", pkColumnName = "key", valueColumnName = "valor", pkColumnValue = "ID_HOTEL")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "HOTEL_GEN")
	private long id;

	@Column(unique = true)
	private int codHotel;

	private String name;

	private String quality;

	private String endereco;

	private String cidade;

	private String cep;

	private String latitude;

	private String longitude;

	private String linkImage;

	private String linkSelection;

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "hotel")
	private List<Image> listImage;

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "hotel")
	private List<RoomModel> listRoomType;

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "hotel")
	private List<BookHotel> listBooks;

	@ManyToMany(fetch = FetchType.EAGER, targetEntity = Destination.class)
	@JoinTable(name = "T_HOTEL_DESTINATION", joinColumns = @JoinColumn(name = "HOTEL_ID", referencedColumnName = "ID_HOTEL"), inverseJoinColumns = @JoinColumn(name = "DESTINATION_ID", referencedColumnName = "ID_DESTINATION"))
	private List<Destination> destinations;

	@Temporal(value = TemporalType.DATE)
	private Date lastUpdate;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getCodHotel() {
		return codHotel;
	}

	public void setCodHotel(int codHotel) {
		this.codHotel = codHotel;
	}

	public String getEndereco() {
		return endereco;
	}

	public void setEndereco(String endereco) {
		this.endereco = endereco;
	}

	public String getCidade() {
		return cidade;
	}

	public void setCidade(String cidade) {
		this.cidade = cidade;
	}

	public String getCep() {
		return cep;
	}

	public void setCep(String cep) {
		this.cep = cep;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public List<Image> getListImage() {
		return listImage;
	}

	public void setListImage(List<Image> listImage) {
		this.listImage = listImage;
	}

	public List<RoomModel> getListRoomType() {
		return listRoomType;
	}

	public void setListRoomType(List<RoomModel> listRoomType) {
		this.listRoomType = listRoomType;
	}

	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	public List<BookHotel> getListBooks() {
		return listBooks;
	}

	public void setListBooks(List<BookHotel> listBooks) {
		this.listBooks = listBooks;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getQuality() {
		return quality;
	}

	public void setQuality(String quality) {
		this.quality = quality;
	}

	public String getLinkImage() {
		return linkImage;
	}

	public void setLinkImage(String linkImage) {
		this.linkImage = linkImage;
	}

	public String getLinkSelection() {
		return linkSelection;
	}

	public void setLinkSelection(String linkSelection) {
		this.linkSelection = linkSelection;
	}

	public List<Destination> getDestinations() {
		return destinations;
	}

	public void setDestinations(List<Destination> destinations) {
		this.destinations = destinations;
	}

	@Override
	public String toString() {
		return "Hotel [id=" + id + ", codHotel=" + codHotel + ", name=" + name
				+ ", quality=" + quality + ", endereco=" + endereco
				+ ", cidade=" + cidade + ", cep=" + cep + ", latitude="
				+ latitude + ", longitude=" + longitude + ", listImage="
				+ listImage + ", listRoomType=" + listRoomType + ", listBooks="
				+ listBooks + ", lastUpdate=" + lastUpdate + "]";
	}

}
